/**
 * Created by lenovo on 2019/1/26.
 */

function NewsList() {

}

NewsList.prototype.run = function () {
   var self = this;
   self.listenSubmitEvent()
};

NewsList.prototype.listenSubmitEvent = function () {
    var submitBtn = $('.submit-btn');
    var textarea = $('textarea[name="comment"]');
    submitBtn.click(function () {
        var content = textarea.val();
        var news_id = submitBtn.attr('data-news-id');
        xfzajax.post({
            'url':'/news/public_comment/',
            'data':{
                'content':content,
                'news_id':news_id
            },
            'success':function (result) {
                if(result['code']===200){
                    var comment = result['data'];
                    var tpl = template('comment-item',{'comment':comment});
                    var commentList = $(".comment-list");
                    commentList.prepend(tpl);
                    window.messageBox.showSuccess('恭喜，评论发表成功！');
                    textarea.val('')
                }
            }
        })
    })
};

$(function () {
   var newsList = new NewsList();
   newsList.run()
});